package agu.misc;

import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;

public class ActivityLifecycleCallback2 implements ActivityLifecycleCallbacks
{
    public interface LifecycleEventCallback
    {
        void onLifecycleEventCallback(@NonNull Activity activity, Lifecycle.Event event);
    }

    LifecycleEventCallback cb;

    public ActivityLifecycleCallback2(LifecycleEventCallback cb){
        this.cb = cb;
    }

    @Override
    public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_CREATE);
    }

    @Override
    public void onActivityStarted(@NonNull Activity activity){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_START);
    }

    @Override
    public void onActivityResumed(@NonNull Activity activity){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_RESUME);
    }

    @Override
    public void onActivityPaused(@NonNull Activity activity){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_PAUSE);
    }

    @Override
    public void onActivityStopped(@NonNull Activity activity){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_STOP);
    }

    @Override
    public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle){
    }

    @Override
    public void onActivityDestroyed(@NonNull Activity activity){
        if(cb != null) cb.onLifecycleEventCallback(activity, Lifecycle.Event.ON_DESTROY);
    }
}
